package database.access.layer;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class AuthenticationDal {
	protected ConnectionManager mgr = null;
	protected Connection con = null;
	
	public AuthenticationDal(){
		
	}
	
	public boolean makeAuthentication(String email, String password) throws SQLException{
		this.mgr = ConnectionManager.getInstance();
		this.con = mgr.getConnection();
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery("select * from USER where email = '"+email+"' and password = '"+password+"'");
		rs.next();
		if(rs.getString(4).equals(email) && rs.getString(5).equals(password)){
			rs.close();
			st.close();
			mgr.closeConnection(con);
			return true;
		}
		else{
			rs.close();
			st.close();
			mgr.closeConnection(con);
			return false;
		}
	}
}
